<?php
/**
 * @description : Mstat Report Tool entrance file.
 * @author : stephen.mo <stephen.mo@achievo.com>
 * @date : 2010-04-12
 */

//require the pworks lib.
ini_set('display_errors','on');
require_once('TVB/PWORKS/mvc/FrontController.class.php');
require_once('TVB/PWORKS/mvc/DefaultSystemDataHelper.class.php');
require_once('TVB/PWORKS/mvc/CachedConfigHelper.class.php');
require_once('TVB/PWORKS/common/cache/impl/SimpleCacheHelper.class.php');
require_once('TVB/PWORKS/common/cache/impl/ApcCache.class.php');
require_once('TVB/PWORKS/util/DebugUtil.class.php');
require_once('TVB/PWORKS/mvc/result/PageLoader.class.php');

require_once('TVB/CmsFramework/v2/require.php');
require_once 'TVB/mytvplus/MstatReportTool/common/bootstrap.php';

// Debug codes for developing
$debug = isset($_REQUEST['__debug'])?$_REQUEST['__debug']:false;
DebugUtil::$enable = $debug;
$refCache = isset($_REQUEST['__clean_cache'])?$_REQUEST['__clean_cache']:false;
if($refCache) apc_clear_cache('user');

try{
    //set config helper
    $confHelper = new CachedConfigHelper();
    $confCacheHelper = new SimpleCacheHelper();
    $confCacheHelper->setGroup('mstat-report-tool-app-conf');
    $confCacheHelper->setCache(new ApcCache(), 1);
    $confHelper->setCacheHelper($confCacheHelper);
    $doConfigCheck = false;
    $confHelper->init(AC::REPORT_TOOL_CONFIG_FILE, $doConfigCheck);
    $service_get_country = AC::$service_get_country;
    $video_bitrate_default = '["'.implode('","',AC::getInstance()->getConfigSetting(AC::$video_bitrates)).'"]';


    CmsManager::set('cdn_path','./cdn/');
    CmsManager::set('app_tpl_root', '/opt/php/lib/php/TVB/mytvplus/MstatReportTool/view/');
    CmsManager::set('skin','default');
    CmsManager::initDefaultRefs();
    $css = "<style>
                //body{background:#eee;}
            </style>
            <script>
            var mConfigs = {
                VIDEO_BITRATES:".$video_bitrate_default.",
                URL: {
                    GET_COUNTRY: '".$service_get_country."'
                }
            };
            </script>";

    $js =  '<script>
                window.status += " - inline js active";
            </script>';

    //add embedcontent.
    CmsManager::addEmbedContent(
        array(
            'css_inline'=>array($css,'project.css'),
            'js_inline' =>array($js),
            'js_init' =>array('jquery.autocomplete.js','canvas.js','project-init.js')
            )
    );

    #CmsFramework
    $pageCfgCache = new SimpleCacheHelper();
    $pageCfgCache->setGroup('report-tool-cms-page-obj');
    $pageCfgCache->setCache(new ApcCache(), 1);
    PageLoader::$cacheHelper = PageConfigHelper::$cacheHelper = $pageCfgCache;
    $pageConfigHelper = new PageConfigHelper;
    $pageConfigHelper->init(AC::REPORT_TOOL_PAGES_FILE);
    #CmsFramework

    FrontController::$confHelper = $confHelper;

    //set data input helper
    FrontController::$dataHelper = new DefaultSystemDataHelper();

    //set cache helper
    $appCacheHelper = new SimpleCacheHelper();
    $appCacheHelper->setGroup('report-tool-app-obj');
    $appCacheHelper->setCache(new ApcCache(), 1);
    FrontController::$cacheHelper = $appCacheHelper;

    //startup
    FrontController::start();

}
catch(SystemException $e) {
    if($debug){
        echo "<h3>SystemException</h3>";
        echo "<B>ID:</B>". $e->id;
        echo "<br>";
        echo "<B>TYPE:</B>". $e->type;
        echo "<br>";
        echo '<B>MESSAGE:</B><font size="4" color="red">';
        echo $e->message;
        echo "</font>";
        echo "<br>";
    }
}


?>